package com.gzsxy.esjy.service.core.sign.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.gzsxy.esjy.common.base.exception.impl.CustomAssert;
import com.gzsxy.esjy.service.core.sign.dao.ElectronicSealMapper;
import com.gzsxy.esjy.service.core.sign.dto.ElectronicSealDto;
import com.gzsxy.esjy.service.core.sign.entity.ElectronicSeal;
import com.gzsxy.esjy.service.core.sign.service.ElectronicSealService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ElectronicSealServiceImpl extends ServiceImpl<ElectronicSealMapper, ElectronicSeal>  implements ElectronicSealService {

    @Autowired
    private ElectronicSealMapper electronicSealMapper;

    /**
     * 添加公章
     * @param sealDto
     */
    @Override
    public void addSeal(ElectronicSealDto sealDto) {
        LambdaQueryWrapper<ElectronicSeal> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(ElectronicSeal::getSealType,sealDto.getSealType())
                .eq(ElectronicSeal::getOrgCode,sealDto.getOrgCode());
        Long count = electronicSealMapper.selectCount(wrapper);
        CustomAssert.notTrue(0 == count,"当前部门已存在公章");

        ElectronicSeal electronicSeal = new ElectronicSeal();
        BeanUtils.copyProperties(sealDto,electronicSeal);
        electronicSeal.setUploadUser("admin");
        electronicSeal.setUploadUser("admin");
        electronicSealMapper.insert(electronicSeal);
    }
}
